#include "FTPServices.h"
#include "SConsoleStats.h"
#include "StructList.h"

extern int errno;

int FTPServicesMain(int fd)
{
    int cc;
    SDataMessage msg;

    cc = read(fd,&msg,sizeof(SDataMessage));
    if(cc<0)
       {
          printf("chatter read:%s\n",strerror(errno));
          return 0;
       }
    if(cc>0)
    {
        if(AnalyMessage(&msg))
        {
            if(HandleMessage(&msg,fd))
            {

            }
            else
            {
                //write(fd,"2",1);//错误代码2，处理命令失败，有非法内容
                printf("erre code 2: handle msg failed \n");
                write(fd,"-1",2);
            }
        }
        else
        {
            // write(fd,"1",1);//错误代码1：解析命令失败，格式错误
            printf("erre code 1: analy msg failed \n");
        }
    }
    if(fd>0)
        close(fd);
    return 0;
}

int AnalyMessage(SDataMessage* msg)
{
    //获取控制命令

    return 1;
}

int HandleMessage(SDataMessage* msg,int fd)
{
    int tag= 0;
    if(!msg)
        return 0;
    switch(msg->msgtype)
    {
    case EMT_NOPEN :
    tag = ServiceDoNetOpen(msg,fd);
    break;
    case EMT_NUSER:
        break;
    case EMT_NDIR :
        break;
    case EMT_NCD:
        break;
    case EMT_NMKDIR:
        break;
    case EMT_NMRDIR:
        break;
    case EMT_NPUT:
        break;
    case EMT_NGET:
        break;
    case EMT_NDELETE:
        break;
    default:
        return tag;
        break;
    }
    return tag;
}


int ServiceDoNetOpen(SDataMessage* msg,int fd)
{
    char*  pcHello= "hello\0";
    if(WriteBuf(fd,pcHello,strlen(pcHello)))
        return 1;

    return 0;
}

int ServiceDoNetUser(SDataMessage* msg,int fd)
{

    return 0;
}

int ServiceDoNetDir(SDataMessage* msg,int fd)
{

    return 0;
}

int ServiceDoNetCd(SDataMessage* msg,int fd)
{

    return 0;
}

int ServiceDoNetMkDir(SDataMessage* msg,int fd)
{

    return 0;
}

int ServiceDoNetMrDir(SDataMessage* msg,int fd)
{

    return 0;
}

int ServiceDoNetPut(SDataMessage* msg,int fd)
{

    return 0;
}

int ServiceDoNetGet(SDataMessage* msg,int fd)
{

    return 0;
}
